home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / utils / bibtools / bibkey < prev    next >
Text File  |  1992-09-03  |  1KB  |  57 lines

  1. #!/bin/csh -f
  2. # bibkey - look for a word in the keyword field
  3. # in the references in a BiBTeX file. A restricted form of looktex, in
  4. # that bibkey only looks at "keyword" fields of the entries.
  5. #
  6. # David Kotz (dfk@cs.dartmouth.edu)
  7. #
  8. # usage: 
  9. #  bibkey keyword file...
  10. #
  11. # Warning: Any characters in keyword that have meanings in regexps
  12. # used by either sed or egrep must be escaped with a \ (the most 
  13. # likely occurrence might be \ itself: use \\). Case is ignored in 
  14. # the search.
  15. #
  16. # Multiple keywords may be specified with an egrep alternation format:
  17. # eg  bibkey 'jones|smith' foo.bib
  18. #
  19. # Actually, any egrep expression is allowed. 
  20. # Be sure to quote it properly. 
  21. #
  22.  
  23. set L=~/lib
  24.  
  25. if ($#argv < 2) then
  26.     echo usage: bibkey keyword 'file...'
  27.     exit 1
  28. endif
  29.  
  30. set keyword=`echo "$1" | tr A-Z a-z`
  31. shift
  32.  
  33. set script=/tmp/bibkey$$
  34. onintr cleanup
  35.  
  36. # Search for the keyword and get a script for extracting the
  37. # references:
  38. #  Cat the files
  39. #  Strip comment lines and comments on lines
  40. #  Translate to lower case (needs to precede sed and egrep)
  41. #  Extract the keyword entries, plus number for lines with @
  42. #  Search for the keyword
  43. #  Convert this output into a sed script
  44. cat $* \
  45.     | sed -e 's/^%.*//' -e 's/\([^\\]\)%.*/\1/' \
  46.     | tr A-Z a-z \
  47.     | sed -n -f $L/bibkey.sed \
  48.     | egrep '^[0-9]*$|'"($keyword)" \
  49.     | awk -f $L/bibkey.awk > $script
  50.  
  51. # Now have sed print out the correct entries:
  52. cat $* | sed -n -f $script 
  53.  
  54. cleanup:
  55. rm -f $script
  56.